package com.cevent.community.app.common.config;/**
 * Created by Cevent on 2021/9/16.
 */

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author cevent
 * @description 验证码配置
 * @date 2021/9/16 14:48
 */
@Configuration
public class CaptchaConfig {
    //注入bean，默认验证码
    @Bean
    public DefaultKaptcha getDefaultKaptcha(){
        DefaultKaptcha defaultKaptcha=new DefaultKaptcha();
        //创建验证码属性
        Properties properties=new Properties();
        properties.setProperty("kaptcha.border","no");
        //验证码图片颜色配置
        properties.setProperty("kaptcha.border.color", "105,179,90");
        //字体颜色，233,32,16橘色
        properties.setProperty("kaptcha.textproducer.font.color", "243,255,255");
        //字体
        properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
        //图片宽度
        properties.setProperty("kaptcha.image.width", "130");
        //图片高度
        properties.setProperty("kaptcha.image.height", "40");
        //字体大小
        properties.setProperty("kaptcha.textproducer.font.size", "25");
        //干扰线
        properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise");
        properties.setProperty("kaptcha.noise.color","143,203,215");
        //背景色
        properties.setProperty("kaptcha.background.clear.from","52,182,17");
        properties.setProperty("kaptcha.background.clear.to","36,110,16");
        properties.setProperty("kaptcha.session.key", "code");
        properties.setProperty("kaptcha.textproducer.char.length", "4");
        properties.setProperty("kaptcha.textproducer.font.names", "Arial");
        /*properties.setProperty("kaptcha.noise.color", "64,158,255");
        properties.setProperty("kaptcha.noise.impl", "com.google.code.kaptcha.impl.NoNoise");*/
        //图片样式
        properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");
        //WaterRipple
        //properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.FishEyeGimpy");
        //properties.setProperty("kaptcha.obscurificator.impl", "com.google.code.kaptcha.impl.ShadowGimpy");
        //使用properties配置项创建验证码
        Config config=new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}
